<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <div class="layui-row layui-col-space10" id="main1">

        </div>
        <script type="text/html" id="currentTableBar">
          <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="query">查看合同</a>

        </script>

    </div>
</div>

<script>
    layui.use(['form', 'table','miniPage','element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            element=layui.element;
            miniPage = layui.miniPage;

        table.render({
            elem: '#currentTableId',
            url: SURL+'rentinfo/queryRentinfoeAll2',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                // {type: "checkbox", width: 50},
                // {field: 'id', width: 80, title: 'ID', sort: true},
                {templet:'<div>{{d.houses.numbers}}</div>',width: 100, title: '房屋编号'},
                {templet:'<div>{{d.customer.custname}}</div>',width: 80, title: '租赁人'},
                {templet:'<div>{{d.customer.identity}}</div>',width: 120, title: '身份证号'},
                {templet:'<div>{{d.customer.phone}}</div>',width: 120, title: '联系方式'},
                {templet:'<div>{{d.contract.money}}</div>',width: 80, title: '租价'},
                {templet:'<div>{{d.houses.address}}</div>',width: 150, title: '房地址'},
                {filed:'status',title: '租房状态',width: 100,
                    templet: function(res){
                      if(res.status=='1'){
                          return '<span class="layui-badge layui-bg-red">已经退租</span>';
                      }else{
                          return '<span class="layui-badge layui-bg-green">正在租赁中..</span>';
                      }
                    }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            id:'testReload',
            skin: 'line'
        });



        //根据合同id查询合同相关的租赁信息以及客户和房东信息
        function queryByID(id,element){
            $.ajax({
                url:SURL+"contract/queryById?id="+id,
                type:"POST",
                data:{"id":id},
                success:function(data){
                    //渲染数据操作
                    $("#chuzu").html(data.czf);
                    $("#zuke").html(data.zlf);
                    $("#address").html(data.address);
                    $("#kssj").html(data.kssj);
                    $("#jssj").html(data.jssj);
                    $("#price").html(data.price);
                    element.init();
                }
            })
            return false;
        };


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            console.log(data)
            debugger
            if (obj.event === 'query') {
                var content = miniPage.getHrefContent('page/rent/hetong.html');
                var openWH = miniPage.getOpenWidthHeight();
                var index = layer.open({
                    title: '查看合同',
                    type: 1,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                //查询合同id对应的值信息
                queryByID(obj.data.contractId,element);
                $(window).on("resize", function () {
                    layer.full(myrent);
                });
                return false;
            }
        });
    });
</script>